from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-31 14:12:27.765995
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 31, Oct, 2022
Time: 14:12:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8730
Nobs: 826.000 HQIC: -51.1898
Log likelihood: 10764.4 FPE: 4.81882e-23
AIC: -51.3869 Det(Omega_mle): 4.32419e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.292296 0.051360 5.691 0.000
L1.Burgenland 0.108952 0.035043 3.109 0.002
L1.Kärnten -0.106681 0.018667 -5.715 0.000
L1.Niederösterreich 0.211143 0.073309 2.880 0.004
L1.Oberösterreich 0.102054 0.070171 1.454 0.146
L1.Salzburg 0.249445 0.037267 6.694 0.000
L1.Steiermark 0.036722 0.048816 0.752 0.452
L1.Tirol 0.107065 0.039612 2.703 0.007
L1.Vorarlberg -0.057907 0.034066 -1.700 0.089
L1.Wien 0.061243 0.062690 0.977 0.329
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064419 0.106180 0.607 0.544
L1.Burgenland -0.032576 0.072447 -0.450 0.653
L1.Kärnten 0.047622 0.038591 1.234 0.217
L1.Niederösterreich -0.172048 0.151556 -1.135 0.256
L1.Oberösterreich 0.383667 0.145070 2.645 0.008
L1.Salzburg 0.286304 0.077044 3.716 0.000
L1.Steiermark 0.104646 0.100921 1.037 0.300
L1.Tirol 0.314457 0.081893 3.840 0.000
L1.Vorarlberg 0.024962 0.070428 0.354 0.723
L1.Wien -0.014820 0.129604 -0.114 0.909
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190383 0.026374 7.219 0.000
L1.Burgenland 0.090778 0.017995 5.045 0.000
L1.Kärnten -0.008483 0.009586 -0.885 0.376
L1.Niederösterreich 0.264905 0.037645 7.037 0.000
L1.Oberösterreich 0.125151 0.036034 3.473 0.001
L1.Salzburg 0.048262 0.019137 2.522 0.012
L1.Steiermark 0.016811 0.025068 0.671 0.502
L1.Tirol 0.094666 0.020341 4.654 0.000
L1.Vorarlberg 0.058945 0.017494 3.370 0.001
L1.Wien 0.119620 0.032192 3.716 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104956 0.027044 3.881 0.000
L1.Burgenland 0.045131 0.018452 2.446 0.014
L1.Kärnten -0.016268 0.009829 -1.655 0.098
L1.Niederösterreich 0.194185 0.038601 5.031 0.000
L1.Oberösterreich 0.293154 0.036949 7.934 0.000
L1.Salzburg 0.116032 0.019623 5.913 0.000
L1.Steiermark 0.099926 0.025704 3.888 0.000
L1.Tirol 0.117543 0.020858 5.635 0.000
L1.Vorarlberg 0.071176 0.017938 3.968 0.000
L1.Wien -0.026458 0.033010 -0.802 0.423
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121007 0.049181 2.460 0.014
L1.Burgenland -0.049755 0.033557 -1.483 0.138
L1.Kärnten -0.040483 0.017875 -2.265 0.024
L1.Niederösterreich 0.169592 0.070199 2.416 0.016
L1.Oberösterreich 0.137742 0.067195 2.050 0.040
L1.Salzburg 0.283954 0.035686 7.957 0.000
L1.Steiermark 0.034365 0.046746 0.735 0.462
L1.Tirol 0.166111 0.037932 4.379 0.000
L1.Vorarlberg 0.105958 0.032621 3.248 0.001
L1.Wien 0.073294 0.060031 1.221 0.222
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057332 0.038891 1.474 0.140
L1.Burgenland 0.039897 0.026536 1.504 0.133
L1.Kärnten 0.050322 0.014135 3.560 0.000
L1.Niederösterreich 0.225728 0.055511 4.066 0.000
L1.Oberösterreich 0.282421 0.053136 5.315 0.000
L1.Salzburg 0.052527 0.028219 1.861 0.063
L1.Steiermark -0.008699 0.036965 -0.235 0.814
L1.Tirol 0.151077 0.029995 5.037 0.000
L1.Vorarlberg 0.070826 0.025796 2.746 0.006
L1.Wien 0.079440 0.047471 1.673 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171941 0.046479 3.699 0.000
L1.Burgenland -0.005208 0.031713 -0.164 0.870
L1.Kärnten -0.061416 0.016893 -3.636 0.000
L1.Niederösterreich -0.083163 0.066342 -1.254 0.210
L1.Oberösterreich 0.193572 0.063502 3.048 0.002
L1.Salzburg 0.057285 0.033725 1.699 0.089
L1.Steiermark 0.228867 0.044177 5.181 0.000
L1.Tirol 0.495492 0.035848 13.822 0.000
L1.Vorarlberg 0.050656 0.030829 1.643 0.100
L1.Wien -0.046124 0.056733 -0.813 0.416
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153021 0.053278 2.872 0.004
L1.Burgenland -0.010965 0.036352 -0.302 0.763
L1.Kärnten 0.065608 0.019364 3.388 0.001
L1.Niederösterreich 0.200686 0.076046 2.639 0.008
L1.Oberösterreich -0.059221 0.072792 -0.814 0.416
L1.Salzburg 0.218075 0.038658 5.641 0.000
L1.Steiermark 0.113999 0.050639 2.251 0.024
L1.Tirol 0.079079 0.041091 1.924 0.054
L1.Vorarlberg 0.125362 0.035339 3.547 0.000
L1.Wien 0.116008 0.065032 1.784 0.074
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350479 0.031080 11.277 0.000
L1.Burgenland 0.006387 0.021206 0.301 0.763
L1.Kärnten -0.023745 0.011296 -2.102 0.036
L1.Niederösterreich 0.224307 0.044363 5.056 0.000
L1.Oberösterreich 0.174572 0.042464 4.111 0.000
L1.Salzburg 0.047860 0.022552 2.122 0.034
L1.Steiermark -0.016477 0.029541 -0.558 0.577
L1.Tirol 0.109924 0.023971 4.586 0.000
L1.Vorarlberg 0.074122 0.020615 3.595 0.000
L1.Wien 0.053621 0.037937 1.413 0.158
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041967 0.153294 0.190606 0.160258 0.125693 0.116322 0.066340 0.227821
Kärnten 0.041967 1.000000 -0.002117 0.129931 0.042560 0.096864 0.429039 -0.052854 0.101372
Niederösterreich 0.153294 -0.002117 1.000000 0.337095 0.157134 0.301076 0.113469 0.183879 0.329695
Oberösterreich 0.190606 0.129931 0.337095 1.000000 0.234858 0.333043 0.174985 0.173802 0.264122
Salzburg 0.160258 0.042560 0.157134 0.234858 1.000000 0.147720 0.132049 0.149443 0.137656
Steiermark 0.125693 0.096864 0.301076 0.333043 0.147720 1.000000 0.154809 0.141835 0.080222
Tirol 0.116322 0.429039 0.113469 0.174985 0.132049 0.154809 1.000000 0.116007 0.157473
Vorarlberg 0.066340 -0.052854 0.183879 0.173802 0.149443 0.141835 0.116007 1.000000 0.008270
Wien 0.227821 0.101372 0.329695 0.264122 0.137656 0.080222 0.157473 0.008270 1.000000